package com.oracle.zebrafreelytraveling.ui.adapter;

import android.content.Context;
import android.view.View;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.oracle.zebrafreelytraveling.R;
import com.oracle.zebrafreelytraveling.data.RequestResult.ResCircle;
import com.oracle.zebrafreelytraveling.ui.BaseRecycleAdapter.CommonAdapter;
import com.oracle.zebrafreelytraveling.ui.BaseRecycleAdapter.base.ViewHolder;
import com.oracle.zebrafreelytraveling.utils.StringUtil;
import com.oracle.zebrafreelytraveling.utils.constant.Constant;
import com.zhy.view.flowlayout.FlowLayout;
import com.zhy.view.flowlayout.TagAdapter;
import com.zhy.view.flowlayout.TagFlowLayout;

import java.util.List;

/**
 * Created by yydcnjjw on 2017/8/10.
 */

public class CircleListAdapter extends CommonAdapter<ResCircle.DataBean> {

    public CircleListAdapter(Context context, int layoutId, List<ResCircle.DataBean> datas) {
        super(context, layoutId, datas);
    }

    @Override
    protected void convert(ViewHolder holder, ResCircle.DataBean circle, int position) {
        SimpleDraweeView mCircleImage = holder.getView(R.id.circle_image);
        mCircleImage.setImageURI(Constant.DOWNLOAD_URL + circle.getCircle().getHeadImg());
        holder.setText(R.id.circle_name, circle.getCircle().getName());
        holder.setText(R.id.circle_intro, circle.getCircle().getIntro());
        TagFlowLayout layout = holder.getView(R.id.circle_label);
        if (circle.getCircle().getLabel() != null){
            String[] labelList = StringUtil.formatLabelList(circle.getCircle().getLabel());
            layout.setAdapter(new TagAdapter<String>(labelList) {
                @Override
                public View getView(FlowLayout parent, int position, String o) {
                    TextView tv = (TextView) mInflater.inflate(R.layout.tag_circle_label_tv,
                            layout, false);
                    tv.setText(o);
                    return tv;
                }
            });
        }
        holder.setText(R.id.circle_account_num, circle.getCircle().getUserNum() + "");
        holder.setText(R.id.circle_view, circle.getPlace().getPlaceName());
    }
}
